home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / wexmast / w2menus.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  152 lines

  1. ; $Id: w2menus.pro,v 1.4 1997/01/15 04:29:15 ali Exp $
  2. ;
  3. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ; This is the code for a more elaborate menu example.
  7. ; In this example, two menus with identical menu items
  8. ; are managed.  The menus in this example were made without
  9. ; the use of either the /EXCLUSIVE or /NONEXCLUSIVE keywords
  10. ; to the XMENU routine.  As a result, the menus look like 
  11. ; "action" buttons instead of button lists.
  12.  
  13.  
  14.  
  15.  
  16. PRO w2menus_event, event
  17.  
  18. ; This is the event handler for a widget with two menus.  Note that
  19. ; the buttons and the user values of the buttons are identical.  The
  20. ; example illustrates two methods of determining which button was
  21. ; selected.
  22.  
  23. ; The first method uses the event id of the button group.
  24. ; This allows the procedure to perform some action based on which menu
  25. ; was used, but does not differentiate between buttons within that menu.
  26.  
  27. ; The second method uses the event value to determine which button was
  28. ; selected.  Note that since the user values of the two menus are the
  29. ; same, the corresponding buttons from both menus will be handled by
  30. ; the same branch of the case statement.  This method allows the
  31. ; procedure to perform some action based on the user value of the
  32. ; particular button, but does not necessarily differentiate between
  33. ; menus.  Usually the user values of buttons in different menus are
  34. ; different, but they need not be.
  35.  
  36. ; The COMMON block is used because both w2menus and w2menus_event must
  37. ; know about all widgets that will generate values:
  38.  
  39. COMMON w2menusblock, first_menu_id, second_menu_id
  40.  
  41. ; Determine whether the menu selection came from the first menu.
  42. ; If it did, set the menu number.
  43.  
  44. IF event.id EQ first_menu_id THEN BEGIN
  45.     ; perform some action particular to menu one
  46.     PRINT, ' ' 
  47.     PRINT, 'Button selected from first menu.'
  48.     menu_number=1
  49. ENDIF
  50.  
  51. ; Determine whether the menu selection came from the second menu.
  52. ; If it did, set the menu number.
  53. IF event.id EQ second_menu_id THEN BEGIN
  54.     ; perform some action particular to menu two
  55.     PRINT, ' '
  56.     PRINT, 'Button selected from second menu.'
  57.     menu_number=2
  58. ENDIF
  59.  
  60. ; Perform actions based on the user value of the button which was pressed.
  61. ; Note that a branch of the case statement may handle two buttons from
  62. ; different menus which have the same user value.  The user value of buttons
  63. ; is likely to be different in most applications, but these are the same
  64. ; in order to illustrate how they may be handled by the event handler.
  65.  
  66. CASE event.value OF
  67.     'ONE':BEGIN
  68.         PRINT, 'Menu Selected:    ', menu_number
  69.         PRINT, 'Button Selected:    ', event.value        
  70.         END
  71.  
  72.     'TWO':BEGIN
  73.         PRINT, 'Menu Selected:    ', menu_number
  74.         PRINT, 'Button Selected:    ', event.value        
  75.         END
  76.  
  77.     'QUIT':BEGIN
  78.         PRINT, 'Quitting Two Menu Example'
  79.         WIDGET_CONTROL, event.top, /DESTROY
  80.         END
  81. ENDCASE
  82. END
  83.  
  84.  
  85.  
  86. PRO w2menus, GROUP=GROUP
  87. ; This is the procedure that creates a widget application with two menus.
  88. ; It it used to show two methods for handling the events generated by
  89. ; two menus in the same application.
  90.  
  91. ; The COMMON block is used because both w2menus and w2menus_event must
  92. ; know about all widgets that will generate values:
  93. COMMON w2menusblock, first_menu_id, second_menu_id
  94.  
  95. ; A top-level base widget with the title "Exclusive Buttons Example" will
  96. ; hold the exclusive buttons:
  97.  
  98. base = WIDGET_BASE(TITLE = 'Two Menu Example', $
  99.     /COLUMN, $
  100.     XSIZE=300)
  101.  
  102. ; Set up the button labels.  The button labels will be used not only for
  103. ; the label on the button, but they will also be used for the User Values
  104. ; of the buttons.
  105.  
  106. button_labels = ['ONE', 'TWO', 'QUIT']
  107.  
  108. ; A widget called 'exclus' is created. It has the
  109. ; title: 'Exclusive Menu Widget' 
  110.  
  111. title = WIDGET_BASE(base,/FRAME, /COLUMN)
  112. label = WIDGET_LABEL(title, VALUE='Menu One')
  113. first_menu_id = CW_BGROUP(title, button_labels, $
  114.                           /COLUMN, /FRAME, /RETURN_NAME)
  115.  
  116. title = WIDGET_BASE(base,/FRAME, /COLUMN)
  117. label = WIDGET_LABEL(title, VALUE='Menu Two')
  118. second_menu_id = CW_BGROUP(title, button_labels, $
  119.                            /COLUMN, /FRAME, /RETURN_NAME)
  120.  
  121. ; Realize the widgets:
  122. WIDGET_CONTROL, base, /REALIZE
  123.  
  124. ; Hand off control of the widget to the XMANAGER:
  125. XMANAGER, "w2menus", base, GROUP_LEADER=GROUP, /NO_BLOCK
  126.  
  127. END
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.